#ifndef RULER_H
#define RULER_H

#include <QWidget>
#include <QRect>

class Ruler : public QWidget
{
    Q_OBJECT


public:
    explicit Ruler(QWidget *parent = nullptr);


    qreal unit() const;
    void setUnit(qreal uint);
    int unitSpace() const;
    void setUnitSpace(int space);
    qreal getStart() const;
    void setStart(qreal newStart);

    int space() const;
    void setSpace(int newSpace);

    Qt::Orientation orientation() const;
    void setOrientation(Qt::Orientation newOrientation);
    void setAlign(Qt::Alignment align);
    Qt::Alignment align() const;

private:
    /**
     * @brief getLength 获取标尺显示的长度
     * @return
     */
    int getLength() const;
    QRect calcRect(int offset);
private:
    int m_space = 20;
    int m_unitSpace = 60;    //单位之间的空间
    qreal m_unit = 0.1;
    qreal m_start = 0.0;
    Qt::Orientation m_orientation = Qt::Horizontal;
    Qt::Alignment m_align = Qt::AlignCenter;

public slots:
    void changedStart(QPointF position);
    void changedZoom(int space, qreal unit);


protected:
    void paintEvent(QPaintEvent *event);
};

#endif // RULER_H
